var app = new Vue({
    el: "#app",
    data: {
        musicName: "",  //搜索歌曲名称
        isdoit: false,//修复直接由乐库播放歌曲产生的bhg
        isView1: false, //搜索结果与歌曲信息只出现一个
        isView2: false, //搜索结果与歌曲信息切换按钮
        isView3: false, //是否出现歌曲MV
        isView4: false, //查询历史记录
        isView5: false, //搜索结果与歌曲MV切换
        isViewmenu: true,//菜单
        isViewget1: false,//显示歌单歌曲
        ismenu1: false,
        ismenu1_1: false,
        ismenu2: false,
        isViewget2music: false,//显示歌手歌曲
        ismenu3: false,
        isViewget3: false,
        isViewget4: false,
        ismenu4: false,
        isPlay: false,  //当前歌曲是否播放
        isViewcover:false,
        imgshow:false,
        musicList: [],  //搜索列表
        thisTime: "0",
        thisLyric: "",
        lyrictime: [],
        Lyric: [],
        Time: [],
        keyIndex:"0",
        type: "1",//搜索类型
        offset: "0",// 搜索列表偏移量（换页）
        page: "0", //搜索歌曲页数
        songCount: "0",
        HL: [], //当前的历史记录（短期）
        hl: "", //HL搜索历史的前后页面转换
        L: "0",  //搜索历史的前后页面转换偏移量
        historyList: [],  //搜索历史 （长期）
        newList: [],  //播放列表
        historynewList: [],  //储存播放列表
        newId: "",   //当前播放歌曲Id
        musicUrl: "",   //歌曲地址
        musicCover: "",  //歌曲封面
        newName: "",   //当前歌曲名字
        get1again: false,
        get2again: false,
        get3again: false,
        get4again: false,
        get1_1: "全部",  //获取歌单类型1
        get1_2: "hot",  //获取歌单类型2
        get1_3: [],  //获取歌单
        get1_4: [], //储存歌单歌曲
        get1total: "0",//歌单总数
        get1page: "",//歌单页数
        get1offset: "0",//歌单偏移量（换页）
        get1type1: ["华语", "欧美", "日语", "韩语", "粤语"],
        get1type2: ["流行", "摇滚", "民谣", "电子", "舞曲", "说唱", "轻音乐", "爵士", "乡村", "R&B/Soul", "古典", "民族", "英伦", "金属", "朋克", "蓝调", "雷鬼", "世界音乐", "拉丁", "New Age", "古风", "后摇", "Bossa Nova"],
        get1type3: ["清晨", "夜晚", "学习", "工作", "午休", "下午茶", "地铁", "驾车", "运动", "旅行", "散步", "酒吧"],
        get1type4: ["怀旧", "清新", "浪漫", "伤感", "治愈", "放松", "孤独", "感动", "兴奋", "快乐", "安静", "思念"],
        get1type5: ["综艺", "影视原声", "ACG", "儿童", "校园", "游戏", "70后", "80后", "90后", "网络歌曲", "KTV", "经典", "翻唱", "吉他", "钢琴", "器乐", "榜单", "00后"],
        get2type: "-1", //歌手类型
        get2area: "-1",//歌手地区
        get2initial: "0",//歌手首字母
        get2initials: [],//26字母表
        get2offset: "0",//歌手搜索偏移量
        get2songermusic: [],//储存歌手歌曲
        get2musicoffset: "0",
        get2musictotal: "0",
        get2musictype: "hot",
        get2page: "",
        get2songer: [],//储存歌手信息
        get2newsonger: [],
        get2smessages: [],
        get3area: "全部",
        get3type: "全部",
        get3order: "上升最快",
        get3offset: "0",
        get3MV: [],
        get3MVurl: "",
        get4list: [], //获取并储存榜单
        get4playlist: [], //获取并储存榜单歌曲
        get4nowlist: [],
        hotComments: [],  //热门评论
        isPlaying: false,  //当前歌曲是否播放
        mvUrl: "",  //mv地址
    },
    methods: {
        imgShow:function(){    //显示皮肤列表
            this.imgshow=!this.imgshow;
        },
        get1: function () {    //获得歌单界面
            this.ismenu1 = true;
            this.ismenu2 = false;
            this.ismenu3 = false;
            this.ismenu4 = false;
            if (this.get1again == false) {
                this.$options.methods.get1s.bind(this)(this.get1_1);
            }
        },
        get2: function () {    //获得歌手界面
            this.ismenu1 = false;
            this.ismenu2 = true;
            this.ismenu3 = false;
            this.ismenu4 = false;
            ;
            if (this.get2again == false) {
                this.$options.methods.get2s.bind(this)(this.get2area, this.get2type, this.get2initial)
            }
        },
        get3: function () {    //获得MV界面
            this.ismenu1 = false;
            this.ismenu2 = false;
            this.ismenu3 = true;
            this.ismenu4 = false;
            if (this.get3again == false) {
                this.$options.methods.get3ss.bind(this)(this.get3area, this.get3type, this.get3order);
            }
        },
        get4: function () {    //获得歌单类型
            this.ismenu1 = false;
            this.ismenu2 = false;
            this.ismenu3 = false;
            this.ismenu4 = true;
            if (this.get4again == false) {
                this.$options.methods.get4s.bind(this)();
            }
        },
        get1s: function (get) {  //获得歌单
            this.get1again = true;
            var that = this;
            //console.log(get);
            if (get != this.get1_1) {
                this.get1offset = 0;
            }
            if (get == "R&B/Soul") {
                axios.get("http://test.codeedu.com.cn/wangyiyun/top/playlist?order=" + this.get1_2 + "&cat=R%26B%2FSoul" + "&limit=48&offset=" + (this.get1offset * 48))
                    .then(function (response) {
                        that.get1_3 = response.data.playlists;
                        //console.log(response);
                        //console.log(that.get1_3);               
                        that.get1_1 = get;
                        that.get1total = response.data.total;
                        if (parseInt(that.get1total) % 48 == 0) {
                            that.get1page = (parseInt(that.get1total) / 48);
                        } else {
                            that.get1page = parseInt(parseInt(that.get1total) / 48) + 1;
                        }
                        //console.log(that.get1total);
                        //console.log(that.get1page);
                    }, function (err) { })
                that.ismenu1_1 = false;
            } else {
                axios.get("http://test.codeedu.com.cn/wangyiyun/top/playlist?order=" + this.get1_2 + "&cat=" + get + "&limit=48&offset=" + (this.get1offset * 48))
                    .then(function (response) {
                        that.get1_3 = response.data.playlists;
                        //console.log(response);
                        //console.log(that.get1_3);               
                        that.get1_1 = get;
                        that.get1total = response.data.total;
                        if (parseInt(that.get1total) % 48 == 0) {
                            that.get1page = (parseInt(that.get1total) / 48);
                        } else {
                            that.get1page = parseInt(parseInt(that.get1total) / 48) + 1;
                        }
                        //console.log(that.get1total);
                        //console.log(that.get1page);
                    }, function (err) { })
                that.ismenu1_1 = false;
            }
        },
        //下列分别是首页、上一页、下一页、尾页、改变最新或热门类型、页数跳转、显示歌单
        get1offsettop: function () {
            this.get1offset = 0;
            this.$options.methods.get1s.bind(this)(this.get1_1);
        },
        get1offsetsub: function () {
            this.get1offset--;
            this.$options.methods.get1s.bind(this)(this.get1_1);
        },
        get1offsetadd: function () {
            this.get1offset++;
            this.$options.methods.get1s.bind(this)(this.get1_1);
        },
        get1offsetbot: function () {
            this.get1offset = this.get1page - 1;
            //console.log(this.get1offset);
            this.$options.methods.get1s.bind(this)(this.get1_1);
        },
        get1offsetpage: function (c) {
            if (c != this.get1offset + 1) {
                this.get1offset = c - 1;
                this.$options.methods.get1s.bind(this)(this.get1_1);
            }
        },
        get1ss: function (type) {
            this.get1offset = 0;
            this.get1_2 = type;
            this.$options.methods.get1s.bind(this)(this.get1_1);
        },
        get1jump: function () {
            var a = document.getElementById("get1jump").value;
            if (a > this.get1page) {
                a = this.get1page;
            }
            if (a <= 0) {
                a = 1;
            }
            this.get1offset = a - 1;
            this.$options.methods.get1s.bind(this)(this.get1_1);
        },
        isViewmenu1_1: function () {
            this.ismenu1_1 = !this.ismenu1_1;
            //console.log(this.ismenu1_1);
        },
        get1music: function (item) { //获取歌单里的歌曲
            var that = this;
            axios.get("http://test.codeedu.com.cn/wangyiyun/playlist/detail?id=" + item.id)
                .then(function (response) {
                    //console.log(response);
                    that.get1_4 = response.data.playlist;
                    //console.log(that.get1_4)
                    //console.log(that.get1_4.tracks);
                    that.isViewget1 = true;
                    for (i = 0; i < that.get1_4.tracks.length; i++) {  //对歌曲时间数据进行转换得到正确格式
                        //console.log(that.musicList[i].duration)
                        var d = parseInt(that.get1_4.tracks[i].dt);
                        d = parseInt(d / 1000);
                        var m = parseInt(d / 60);
                        var s = d - 60 * m;
                        if (s < 10) {
                            s = "0" + s;
                        }
                        that.get1_4.tracks[i].duration = m + ":" + s;
                        that.get1_4.tracks[i].artists = that.get1_4.tracks[i].ar;
                        that.get1_4.tracks[i].mvid = that.get1_4.tracks[i].mv;
                    }
                }, function (err) { })
        },   //返回歌单
        returnmenu1: function () {
            this.isViewget1 = false;
        },     
        get2s: function (area, type, initial) {  //获取歌手
            this.get2again = true;
            if (this.get2area != area || this.get2type != type || this.get2initial != initial) {
                this.get2offset = 0;
            }
            //console.log("offset="+this.get2offset);
            var that = this;
            if (initial == 0) {
                axios.get("http://test.codeedu.com.cn/wangyiyun/artist/list?type=" + type + "&area=" + area + "&limit=50&offset=" + (this.get2offset * 50))
                    .then(function (response) {
                        //console.log(response);
                        that.get2songer = response.data.artists;
                    }, function (err) { })
            } else {
                axios.get("http://test.codeedu.com.cn/wangyiyun/artist/list?type=" + type + "&area=" + area + "&limit=50&initial=" + initial + "&offset=" + (this.get2offset * 50))
                    .then(function (response) {
                        //console.log(response);
                        that.get2songer = response.data.artists;
                    }, function (err) { })
            }
            //console.log(that.get2songer);                  
            that.get2area = area;
            that.get2type = type;
            that.get2initial = initial;
        },
        get2ssub: function () {    //上一页
            this.get2offset--;
            //console.log("offset="+this.get2offset);
            this.$options.methods.get2s.bind(this)(this.get2area, this.get2type, this.get2initial);

        },
        get2sadd: function () {    //下一页
            this.get2offset++;
            //console.log("offset="+this.get2offset);
            this.$options.methods.get2s.bind(this)(this.get2area, this.get2type, this.get2initial);

        },
        get2music: function (item) {   //获得歌手的歌曲
            var that = this;
            if (item != this.get2newsonger) {
                this.get2musicoffset = 0;
            }
            axios.get("http://test.codeedu.com.cn/wangyiyun/artist/songs?id=" + item.id + "&order=" + this.get2musictype + "&limit=30&offset=" + (this.get2musicoffset * 30))
                .then(function (response) {
                    //console.log(response);
                    that.get2songermusic = response.data.songs;
                    that.get2musictotal = response.data.total;
                    if (parseInt(that.get2musictotal) % 30 == 0) {
                        that.get2page = (parseInt(that.get2musictotal) / 30);
                    } else {
                        that.get2page = parseInt(parseInt(that.get2musictotal) / 30) + 1;
                    }
                    //console.log(that.get2songermusic);
                    //console.log(that.get2musictotal);
                    //console.log(that.get2page);
                    for (i = 0; i < that.get2songermusic.length; i++) {  //对歌曲时间数据进行转换得到正确格式                  
                        var d = parseInt(that.get2songermusic[i].dt);
                        d = parseInt(d / 1000);
                        var m = parseInt(d / 60);
                        var s = d - 60 * m;
                        if (s < 10) {
                            s = "0" + s;
                        }
                        that.get2songermusic[i].duration = m + ":" + s;
                        that.get2songermusic[i].artists = that.get2songermusic[i].ar;
                        that.get2songermusic[i].mvid = that.get2songermusic[i].mv;
                        //console.log(that.get2songermusic[i].duration);
                        //console.log(that.get2songermusic[i].artists);
                        //console.log(that.get2songermusic[i].mvid);
                        that.isViewget2music = true;
                    }
                }, function (err) { })
            that.get2newsonger = item;
            //console.log(that.get2newsonger);
            this.$options.methods.get2smessage.bind(this)(item);
        },
        get2smessage: function (item) {   //获得歌手信息
            var that = this;
            axios.get("http://test.codeedu.com.cn/wangyiyun/artist/desc?id=" + item.id)
                .then(function (response) {
                    //console.log(response);
                    that.get2smessages = response.data;
                    //console.log(that.get2smessages);
                }, function (err) { })
        },
        //下列分别是首页、上一页、下一页、尾页、点击页数跳转、页数跳转、改变最新或热门类型、显示歌手界面
        get2offsettop: function () {
            this.get2musicoffset = 0;
            this.$options.methods.get2music.bind(this)(this.get2newsonger);
        },
        get2offsetsub: function () {
            this.get2musicoffset--;
            this.$options.methods.get2music.bind(this)(this.get2newsonger);
        },
        get2offsetadd: function () {
            this.get2musicoffset++;
            this.$options.methods.get2music.bind(this)(this.get2newsonger);
        },
        get2offsetbot: function () {
            this.get2musicoffset = this.get2page - 1;
            //console.log(this.get2musicoffset);
            this.$options.methods.get2music.bind(this)(this.get2newsonger);
        },
        get2offsetpage: function (c) {
            if (c != this.get2musicoffset + 1) {
                this.get2musicoffset = c - 1;
                this.$options.methods.get2music.bind(this)(this.get2newsonger);
            }
        },
        get2jump: function () {
            var a = document.getElementById("get2jump").value;
            if (a > this.get2page) {
                a = this.get2page;
            }
            if (a <= 0) {
                a = 1;
            }
            this.get2musicoffset = a - 1;
            this.$options.methods.get2music.bind(this)(this.get2newsonger);
        },
        get2ss: function (type) {
            if (this.get2musictype != type) {
                this.get2musictype = type;
                this.get2musicoffset = 0;
                this.$options.methods.get2music.bind(this)(this.get2newsonger);
            }
        },
        returnmenu2: function () {
            this.isViewget2music = false;
        },
        get3s: function (area, type, order) {  //防止点击同种类型重复请求
            if (this.get3area != area || this.get3type != type || this.get3order != order) {
                this.$options.methods.get3ss.bind(this)(area, type, order);
            }
        },
        get3ss: function (area, type, order) {  //获得MV
            this.get3again = true;
            if (this.get3area != area || this.get3type != type || this.get3order != order) {
                this.get3offset = 0;
            }
            //console.log("offset="+this.get3offset);
            var that = this;
            axios.get("http://test.codeedu.com.cn/wangyiyun/mv/all?&type=" + type + "&area=" + area + "&order=" + order + "&limit=30&offset=" + (this.get3offset * 30))
                .then(function (response) {
                    //console.log(response);
                    that.get3MV = response.data.data;
                    //console.log(that.get3MV);
                }, function (err) { })
            that.get3area = area;
            that.get3type = type;
            that.get3order = order;
            //console.log("offset=" + this.get3offset);
        },
        get3sub: function () {   //上一页
            this.get3offset--;
            this.$options.methods.get3ss.bind(this)(this.get3area, this.get3type, this.get3order);
        },
        get3add: function () {   //下一页
            this.get3offset++;
            this.$options.methods.get3ss.bind(this)(this.get3area, this.get3type, this.get3order);
        },
        get3MVid: function (item) {    //获得MVid
            item.mvid = item.id;
            //console.log(item.mvid);
            var d = parseInt(item.duration);
            d = parseInt(d / 1000);
            var m = parseInt(d / 60);
            var s = d - 60 * m;
            if (s < 10) {
                s = "0" + s;
            }
            item.duration = m + ":" + s;
            this.$options.methods.playMv.bind(this)(item);
        },
        get4s: function () {    //获得榜单
            var that = this;
            axios.get("http://test.codeedu.com.cn/wangyiyun/toplist")
                .then(function (response) {
                    //console.log(response);
                    that.get4list = response.data.list;
                }, function (err) { })
        },
        get4music: function (item) {   //获得榜单音乐
            var that = this;
            axios.get("http://test.codeedu.com.cn/wangyiyun/top/list?id=" + item.id)
                .then(function (response) {
                    //console.log(response);
                    that.get4playlist = response.data.playlist.tracks;
                    for (i = 0; i < that.get4playlist.length; i++) {
                        var d = parseInt(that.get4playlist[i].dt);
                        d = parseInt(d / 1000);
                        var m = parseInt(d / 60);
                        var s = d - 60 * m;
                        if (s < 10) {
                            s = "0" + s;
                        }
                        that.get4playlist[i].duration = m + ":" + s;
                        that.get4playlist[i].artists = that.get4playlist[i].ar;
                        that.get4playlist[i].mvid = that.get4playlist[i].mv;
                    }
                    //console.log(that.get4playlist);
                    that.isViewget4 = true;
                }, function (err) { })
            that.get4nowlist = item;
        },
        returnmenu4: function () {    //显示榜单界面
            this.isViewget4 = false;
        },
        gethistoryList: function () {  //获取历史记录信息
            // for(i=0;i<localStorage.length;i++){
            //     //console.log(i);
            //     if(localStorage.getItem(i)!="null"){
            //         this.historyList[i]=localStorage.getItem(i);
            //         //console.log("localStorage"+localStorage.getItem(i));
            //     }                     
            //     //console.log("historyList"+this.historyList[i]);           
            // } 
            // //console.log("historyList.length="+this.historyList.length);
            // //console.log("localStorage.length"+localStorage.length);
            this.isView4 = !this.isView4;  //打开历史记录
            //console.log("isView4"+this.isView4);
        },
        disappear: function () {   //显示历史记录
            this.isView4 = false;
        },
        clearHistoryList: function () {   //清空历史记录
            this.historyList = [];
            this.isView4=false;
            localStorage.setItem("historyList", JSON.stringify(this.historyList));

        },
        doit1: function () {    //没有用，方便控制台查看
            for (i = 0; i < this.historyList.length; i++) {
                //console.log(i);
                //console.log("historyList" + this.historyList[i]);
            }
            for (i = 0; i < localStorage.length; i++) {
                //console.log(i);
                //console.log("localStorage" + localStorage.getItem(i));
            }
        },
        changemenu: function () {   //显示menu界面
            this.isViewmenu = !this.isViewmenu;
        },
        playMusic: function (item) {//播放歌曲
            if(this.newId != item.id){
                var that = this;
                this.$options.methods.playMusicAgain.bind(this)(item);
                //将该歌曲放入播放列表
                if (that.newList.length == 0) {   //播放列表为空直接将该歌曲放入播放列表
                    that.newList.push(item);
                } else {
                    for (i = 0; i < that.newList.length; i++) {  //防止该歌曲重复放入该播放列表
                        if (item.id == that.newList[i].id) {
                            break;
                        }
                        if (i == that.newList.length - 1) {
                            that.newList.push(item);
                        }
                    }
                }
                localStorage.setItem("newList", JSON.stringify(that.newList));
            }              
        },
        playMusicAgain: function (item) {   //从播放列表里选择播放歌曲
            if(this.newId != item.id){
                var that = this;
            if (item.id != item.mvid) {
                axios.get("http://test.codeedu.com.cn/wangyiyun/song/url?id=" + item.id)
                    .then(function (response) {
                        //console.log(response.data.data[0].url);
                        that.musicUrl = response.data.data[0].url;
                    }, function (err) { })
                axios.get("https://autumnfish.cn/song/detail?ids=" + item.id)
                    .then(function (response) {
                        //console.log(response.data.songs[0].al.picUrl);
                        that.musicCover = response.data.songs[0].al.picUrl;
                    }, function (err) {
                        //console.log(err);
                    })
                axios.get("http://test.codeedu.com.cn/wangyiyun/comment/music?id=" + item.id)
                    .then(function (response) {
                        //console.log(response);
                        that.hotComments = response.data.hotComments;
                    })
                axios.get("http://test.codeedu.com.cn/wangyiyun/lyric?id=" + item.id)
                    .then(function (response) {
                        //console.log(response);
                        that.Time=[];   //清空（防止上一曲歌曲的干扰）
                        that.Lyric=[];  //清空（防止上一曲歌曲的干扰）
                        if(response.data.lrc.lyric!=null){
                            that.thisLyric = response.data.lrc.lyric;
                            that.lyrictime = that.thisLyric.split("\n");  //拆分原歌词文本
                            // //console.log("thisLyric" + that.thisLyric);
                            // //console.log("that.lyrictime" + that.lyrictime);
                            //let lrcexp = new Reg
                            var tempor=[];
                            var min;
                            var s;
                            var allTime=[];
                            var lyr=[];
                            var lyrs=[];
                            for(var i=0; i<that.lyrictime.length; i++) {
                                tempor=that.lyrictime[i];  
                                //console.log("tempor: "+i+" = "+tempor);
                                min=tempor[2];  //取出时间分（笨办法，但是很快啊，不用闪）
                                s=tempor[4]+tempor[5]+tempor[6]+tempor[7];    //取出时间秒（笨办法，但是很快啊，不用闪）
                                allTime.push(parseFloat(s)+parseFloat(min)*60);  //把时间转换为秒的格式（这个精准到秒后一位）
                                lyr[i]=that.lyrictime[i].match(/(?<=])([^"]+)(?=)/g);  //正则表达式获得歌词内容
                                if(lyr[i]!=null){
                                    //console.log(lyr[i][0]);
                                    lyrs.push(lyr[i][0]);
                                }else{
                                    lyrs.push(null);
                                }
                            }
                            that.Time=allTime; //把得到的时间放在Time数组里面
                            that.Lyric=lyrs;  //把得到的歌词放在Lyric数组里面
                            for(i=0;i<that.Lyric.length;i++){
                                if(that.Lyric[i]==null){
                                    that.Lyric.splice(i, 1);
                                    that.Time.splice(i, 1);
                                }
                            }
                        }      
                        //console.log(lyrs);
                        //console.log(that.Lyric);
                        //console.log(that.Time);
                    })
                that.isView1 = false;   //搜索页面关闭
                that.isView2 = true;     //歌曲信息页面出现
                that.isView3 = false;    //关闭歌曲MV页面
                that.isPlay = true;    //歌曲播放状态为true
                that.isView5 = false;  //搜索结果与歌曲MV切换
                that.newName = item.name;   //当前播放歌曲名称
                that.newId = item.id;   //当前播放歌曲ID
                that.isViewmenu=false;
            } else {
                alert("该歌曲只有MV");
                this.$options.methods.playMvAgain.bind(this)(item);
            }
            }
        },
        changeName_music: function (name) {   //点击歌名即可直接搜索
            this.type = 1;
            this.$options.methods.changeName.bind(this)(name);
        },
        changeName_artist: function (name) {   //点击歌星即可直接搜索
            this.type = 1;
            this.$options.methods.changeName.bind(this)(name);
        },
        doit: function () {   //搜索方法
            var that = this;
            this.isView1 = true;      //搜索页面打开
            this.isdoit = true;
            axios.get("http://test.codeedu.com.cn/wangyiyun/search?keywords=" + this.musicName + "&limit=50&type=" + this.type + "&offset=" + this.offset * 50)
                .then(function (response) {
                    //console.log(response);
                    that.musicList = response.data.result.songs;
                    that.songCount = response.data.result.songCount;
                    if (parseInt(that.songCount) % 50 == 0) {
                        that.page = (parseInt(that.songCount) / 50);
                    } else {
                        that.page = parseInt(parseInt(that.songCount) / 50) + 1;
                    }
                    //console.log("page=" + that.page);
                    //console.log(response.data.result.songCount);
                    //console.log(that.songCount);
                    for (i = 0; i < that.musicList.length; i++) {  //对歌曲时间数据进行转换得到正确格式
                        //console.log(that.musicList[i].duration)
                        var d = parseInt(that.musicList[i].duration);
                        d = parseInt(d / 1000);
                        var m = parseInt(d / 60);
                        var s = d - 60 * m;
                        if (s < 10) {
                            s = "0" + s;
                        }
                        that.musicList[i].duration = m + ":" + s;
                        //console.log(m+":"+s);
                        //console.log(that.musicList[i].duration);
                    }
                }, function (err) {
                    //console.log(response);
                })
            if (that.historyList.length == 0) {   //历史搜索列表为空直接将搜索内容放入历史搜索列表
                that.historyList.push(that.musicName);
            }
            else {
                for (i = 0; i < that.historyList.length; i++) {  //防止该搜索内容重复放入该历史搜索列表
                    if (that.musicName == that.historyList[i]) {
                        break;
                    }
                    if (i == that.historyList.length - 1) {
                        that.historyList.push(that.musicName);
                        break;
                    }
                }
            }
            //console.log(that.historyList); 
            if (that.HL.length == 0) {   //历史搜索列表为空直接将搜索内容放入历史搜索列表
                that.HL.push(that.musicName);
                that.hl = 0;
                //console.log(that.hl);
            }
            else {
                for (i = 0; i < that.HL.length; i++) {  //防止该搜索内容重复放入该历史搜索列表
                    if (that.musicName == that.HL[i]) {
                        break;
                    }
                    if (i == that.HL.length - 1) {
                        that.HL.push(that.musicName);
                        that.hl = that.HL.length - 1;
                        that.L = 0;
                        //console.log(that.hl);
                        break;
                    }
                }
            }
            // //console.log(that.HL);   
            // for(i=0;i<that.historyList.length;i++){
            //     localStorage.setItem(i,that.historyList[i]);
            //     var name=localStorage.getItem(i);
            //     //console.log(i);
            //     //console.log(name);
            // }
            localStorage.setItem("historyList", JSON.stringify(that.historyList));
            that.isViewmenu = false;
        },
        //下列分别是首页、上一页、下一页、尾页、改变最新或热门类型、页数跳转
        offsettop: function () { 
            this.offset = 0;
            this.$options.methods.doit.bind(this)();
        },
        offsetadd: function () {
            this.offset++;
            //console.log(this.offset);
            this.$options.methods.doit.bind(this)();
        },
        offsetsub: function () {
            this.offset--;
            this.$options.methods.doit.bind(this)();
        },
        offsetbot: function () {
            if (this.page != 0) {
                this.offset = this.page - 1;
                //console.log(this.get2musicoffset);
                this.$options.methods.doit.bind(this)();
            }
        },
        offsetpage: function (c) {
            if (c != this.coffset + 1) {
                this.offset = c - 1;
                this.$options.methods.doit.bind(this)();
            }
        },
        jump: function () {
            var a = document.getElementById("jump").value;
            if (a > this.page) {
                a = this.page;
            }
            if (a <= 0) {
                a = 1;
            }
            this.offset = a - 1;
            this.$options.methods.doit.bind(this)();
        },
        menudoit: function (item) { //获得音乐url
            var that = this;
            axios.get("http://test.codeedu.com.cn/wangyiyun/song/url?id=" + item.id)
                .then(function (response) {
                    //console.log(response.data.data[0].url);
                    that.musicUrl = response.data.data[0].url;
                }, function (err) { })
        },
        searchMusic: function () {  //搜索歌曲
            if (this.musicName == "") {
                var a = document.getElementById("searchText");
                a.focus();
            } else {
                var that = this;
                this.type = 1;
                this.offset = 0;
                this.$options.methods.doit.bind(this)();
            }
        },
        changeName: function (name) {   //点击歌名或歌星即可直接搜索
            var that = this;
            this.musicName = name;
            this.offset = 0;
            this.$options.methods.doit.bind(this)();
        },
        playMv: function (item) {   //播放MV
            if(this.newId!=item.id){
                var that = this;
            //console.log(item);
            if (item.id != item.mvid) {
                axios.get("https://autumnfish.cn/song/url?id=" + item.id)
                    .then(function (response) {
                        //console.log(response.data.data[0].url);
                        that.musicUrl = response.data.data[0].url;
                    }, function (err) { })
                axios.get("https://autumnfish.cn/comment/hot?type=0&id=" + item.id)
                    .then(function (response) {
                        //console.log(response);
                        that.hotComments = response.data.hotComments;
                    })
                axios.get("https://autumnfish.cn/song/detail?ids=" + item.id)
                    .then(function (response) {
                        //console.log(response.data.songs[0].al.picUrl);
                        that.musicCover = response.data.songs[0].al.picUrl;
                    }, function (err) {
                        //console.log(err);
                    })
            } else {
                axios.get("http://test.codeedu.com.cn/wangyiyun/comment/mv?id=" + item.id)
                    .then(function (response) {
                        //console.log(response);
                        that.hotComments = response.data.hotComments;
                    })
            }
            axios.get("http://test.codeedu.com.cn/wangyiyun/mv/url?id=" + item.mvid)
                .then(function (response) {
                    that.mvUrl = response.data.data.url;
                }, function (err) {
                    //console.log(response);
                })
            that.isView1 = false;  //搜索结果页面关闭
            that.isView2 = false;   //歌曲信息页面关闭
            that.isView3 = true;   //歌曲MV页面打开
            that.isView5 = true;   //搜索结果与歌曲MV切换
            that.newName = item.name;
            that.newId = item.id;
            that.isViewmenu = false;
            //将该歌曲放入播放列表
            if (that.newList.length == 0) {
                that.newList.push(item)
            }
            else {    //防止该歌曲重复放入该播放列表
                for (i = 0; i < that.newList.length; i++) {
                    if (item.id == that.newList[i].id) {
                        break;
                    }
                    if (i == that.newList.length - 1) {
                        that.newList.push(item);
                    }
                }
            }
            localStorage.setItem("newList", JSON.stringify(that.newList));
            }
        },
        playMvAgain: function (item) {   //从列表里播放MV
            if(this.newId!=item.id){
                var that = this;
            axios.get("http://test.codeedu.com.cn/wangyiyun/mv/url?id=" + item.mvid)
                .then(function (response) {
                    that.mvUrl = response.data.data.url;
                }, function (err) {
                    //console.log(response);
                })
            axios.get("http://test.codeedu.com.cn/wangyiyun/comment/mv?id=" + item.id)
                .then(function (response) {
                    //console.log(response);
                    that.hotComments = response.data.hotComments;
                })
            that.isView1 = false;  //搜索结果页面关闭
            that.isView2 = false;   //歌曲信息页面关闭
            that.isView3 = true;   //歌曲MV打开
            that.isView5 = true;    //搜索结果与歌曲MV切换
            that.newName = item.name;
            that.newId = item.id;
            that.isViewmenu = false;
            }  //在播放列表点击播放MV         
        },
        viewcover:function(){  //显示歌曲封面
            this.isViewcover=!this.isViewcover;
        },
        Return: function () {   //搜索结果页面与歌曲信息页面转换按钮
            if (this.isView3 == true) {
                this.isPlay = false;
                this.newId = "";
            }
            this.isView1 = !this.isView1;
            this.isView3 = false;
        },
        Return_: function () {   //搜索结果页面与歌曲MV页面转换按钮
            this.isView1 = !this.isView1;
            this.isView3 = true;
            this.isView5 = true;
        },
        Return__: function () {   //搜索结果页面与歌曲信息页面转换按钮
            if (this.isView3 == true) {
                this.isPlay = false;
                this.newId = "";
            }
            this.isView1 = !this.isView1;
            this.isView3 = false;
        },
        delHistoryList: function (index) {  //删除单个历史记录
            this.historyList.splice(index, 1);
            localStorage.setItem("historyList", JSON.stringify(this.historyList));

        },
        del: function (index) {  //播放列表删除按钮
            this.newList.splice(index, 1);
            localStorage.setItem("newList", JSON.stringify(this.newList));
        },
        Play: function () {    //audio播放
            this.isPlaying = true;
        },
        Pause: function () {   //audio暂停
            this.isPlaying = false;
        },
        changetime:function(index){    //点击歌词跳转
            var a=document.getElementById("audio1");
            a.currentTime=this.Time[index];
            this.isViewcover=true;
        },
        author:function(){  //作者须知
            alert("版权所有©福建师范大学19级\n软工二班刘行风、软工二班黄家明");
        },
    },
})